/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2022. All rights reserved.
 */

import { FileUtil } from '../../utils/file-util.js';
import { JavaCommandBuilder } from '../java-command-builder.js';

export class SigningOptions extends JavaCommandBuilder {
  sign(): SigningOptions {
    this.commandList.push('sign');
    return this;
  }

  addMode(mode: string): SigningOptions {
    this.commandList.push('-mode');
    this.commandList.push(mode);
    return this;
  }

  addProfile(profile: string): SigningOptions {
    FileUtil.checkPathLength(profile);
    this.commandList.push('-profile');
    this.commandList.push(profile);
    return this;
  }

  addSignAlg(signAlg: string): SigningOptions {
    this.commandList.push('-signAlg');
    this.commandList.push(signAlg);
    return this;
  }

  addPrivateKey(privateKey: string): SigningOptions {
    this.commandList.push('-privatekey');
    this.commandList.push(privateKey);
    return this;
  }

  profileSigned(): SigningOptions {
    this.commandList.push('-profileSigned');
    this.commandList.push('1');
    return this;
  }

  addKeyStore(keyStoreFile: string): SigningOptions {
    FileUtil.checkPathLength(keyStoreFile);
    this.commandList.push('-keystore');
    this.commandList.push(keyStoreFile);
    return this;
  }

  addKeyStorePwd(keyStorePwd: string): SigningOptions {
    this.commandList.push('-keystorepasswd');
    this.commandList.push(keyStorePwd);
    return this;
  }

  addKeyAliasPwd(keyAliasPwd: string): SigningOptions {
    this.commandList.push('-keyaliaspasswd');
    this.commandList.push(keyAliasPwd);
    return this;
  }

  addCertPath(certPath: string): SigningOptions {
    FileUtil.checkPathLength(certPath);
    this.commandList.push('-certpath');
    this.commandList.push(certPath);
    return this;
  }

  addKs(ks: string): SigningOptions {
    this.commandList.push('--ks');
    this.commandList.push(ks);
    return this;
  }

  addKsPass(ksPass: string): SigningOptions {
    this.commandList.push('--ks-pass');
    this.commandList.push(ksPass);
    return this;
  }

  addKsKeyAlias(ksKeyAlias: string): SigningOptions {
    this.commandList.push('--ks-key-alias');
    this.commandList.push(ksKeyAlias);
    return this;
  }

  addKeyPass(keyPass: string): SigningOptions {
    this.commandList.push('--key-pass');
    this.commandList.push(keyPass);
    return this;
  }

  addOut(out: string): SigningOptions {
    FileUtil.checkPathLength(out);
    this.commandList.push('--out');
    this.commandList.push(out);
    return this;
  }

  addInputFile(inputFile: string): SigningOptions {
    FileUtil.checkPathLength(inputFile);
    this.commandList.push('-inputFile');
    this.commandList.push(inputFile);
    return this;
  }

  addOutputFile(outputFile: string): SigningOptions {
    FileUtil.checkPathLength(outputFile);
    this.commandList.push('-outputFile');
    this.commandList.push(outputFile);
    return this;
  }

  add(param: string): SigningOptions {
    this.commandList.push(param);
    return this;
  }
}
